package com.minyifang.wcspf.work.ui.user.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.md5.SafeUtils;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.user.view.ForgetPwdNextView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/6/14.
 */
public class ForgetPwdNextPresenter extends BasePresenter<ForgetPwdNextView> {
    public void forgetPwd(String phone, String pwd, String pwdConfirm) {

        Map<String, Object> map = new HashMap<>();
        map.put("phone", phone);
        map.put("password", SafeUtils.getEncryptPwd(pwd));
        map.put("type", "1");

        JSONObject jsonData = Constants.getJsonData(map, null);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().forgetPwd(requestBody), new Consumer<HttpRespond>() {
            @Override
            public void accept(HttpRespond httpRespond) {
                getView().forgetPwdRes(httpRespond);
            }
        });

    }
}
